<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.Set"%>
<%@page import="com.sks.bean.pojo.Config"%>
<%@page import="java.util.List"%>
<%@ include file="../../../cms/page/share/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/sks/cms/page/share/validate.inc" %>
<%@ include file="/sks/js/datePicker.inc" %>
<%

boolean readOnly = StringUtil.toBoolean(request.getAttribute("readOnly"), false);
%>
<title><bean:message key="display.${houseForm.method eq 'edit' ? 'edit' : 'add'}"/><bean:message key="info.house.name"/>&nbsp;三棵松地产</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="租房,买房,三棵松,地产,中介" />
<meta name="description" content="三棵松地产" />
<link rel="stylesheet" href="/css/vip.css" type="text/css">
<%-- <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath %>sks/css/frontpages/BrightSide.css" /> --%>
<link rel="stylesheet" type="text/css" media="screen" href="<%=basePath %>sks/css/frontpages/mytestcss.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<%=basePath %>sks/css/frontpages/deployment.css" />
<script type="text/javascript" src="/js/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/js/jscripts/tiny_mce/button_style/default.js"></script>
<script type="text/javascript" src="/js/jscripts/tiny_mce/button_style/simple.js"></script>
<script language="javascript" type="text/javascript">
<%
if (!readOnly) {
%>
tinyMCE.init(getDefaultButtonStyle("intro,mapInfo"));
//tinyMCE.init(getSimpleButtonStyle("remark"));
<%}%>

function getAreas() {
   var select = document.getElementById('topAreaId');
   var index = select.options[select.selectedIndex].value;
   $.post("/sks/frontpages/privilege/deployment/subarea.do", {method:"getAreasByTopId", areaId:index},
      function (data, textStatus){
         var areaSelect = document.getElementById('areaId');
         while(areaSelect.options.length>0) {
            areaSelect.removeChild(areaSelect.options[0]);
         }
         for (var i=0; i<data.length; i++) {
            var option = document.createElement('option');
            option.innerHTML = data[i].name;
            option.value = data[i].areaId;
            areaSelect.appendChild(option);
         }
         
      }, "json");
}
function getStations() {
   var select = document.getElementById('metroId');
   var index = select.options[select.selectedIndex].value;
   $.post("/sks/frontpages/privilege/deployment/station.do", {method:"getStations", metroId:index},
      function (data, textStatus){
         var stationSelect = document.getElementById('metroStationId');
         while(stationSelect.options.length>0) {
        	 stationSelect.removeChild(stationSelect.options[0]);
         }
         for (var i=0; i<data.length; i++) {
            var option = document.createElement('option');
            option.innerHTML = data[i].name;
            option.value = data[i].stationId;
            stationSelect.appendChild(option);
         }
         
      }, "json");
}
function selectAll(ids, keyCheck) {
	var checks = document.getElementsByName(ids);
	for (var i = 0; i < checks.length; i++) {
		var c = checks[i];
		if (c.type == 'checkbox') {
			c.checked = keyCheck.checked;
		}
	}
}

$(function() {
	$( "#beginDate" ).datepicker({
		changeMonth: true,
		changeYear: true
	});
});
var compareValidator = new tt.CV();
function bodyOnLoad() {
	tt.vf.req.add('title', 'address', 'space');
	tt.vf.int.add("floorAll", "floorAt");
	new tt.LV().set(0, 100).add("title", "community");
	new tt.LV().set(0, 200).add("address", "managePrice");
	//new tt.LV().set(0, 200).add("remark");
	new tt.NRV().set(1, 99999).add("space");//'++'表示无穷大
	new tt.NRV().set(1, 100).add("floorAll", "floorAt");//'++'表示无穷大
	new tt.DV().set("yyyy-mm-dd").add("beginDate");
	var remarkField = new tt.Field("备注", "", "remark").setMsgId("remarkErrorId");
	new tt.LV().set(0, 200).add(remarkField);
	compareValidator.add(new tt.Field("总楼层", "floorAll")).set('n', ">=", new tt.Field("所在楼层", "floorAt"));
	${houseForm.method eq 'edit' ? 'tt.validate();' : ''}
}
function changeBoolean(){
	var saveAndSubmitFlags = document.getElementsByName("saveAndSubmitFlag");
	var saveAndSubmitFlag = saveAndSubmitFlags[0].value;
	if(saveAndSubmitFlag == 'true'){
		saveAndSubmitFlag = false;
	}else{
		saveAndSubmitFlag = true;
	}
	saveAndSubmitFlags[0].value = saveAndSubmitFlag;
}
</script>
</head>
<body onload="bodyOnLoad();" >
	<div class="wrap">
		<jsp:include page="../../header.jsp"></jsp:include>
		<div>
			<div>
				<a href="<%=basePath%>" hidefocus="true">SKS房地产</a> &gt;
				<a href="<%=basePath%>sks/frontpages/privilege/deployment/list.do" target="_self" hidefocus="true">个人中心</a> &gt;
				添加房源
			</div>
			<div class="clear"></div>
		</div>
		<div class="content-wrap">
			<div class="box" align="center">
				<html:form styleId="houseForm"
					action="/sks/frontpages/privilege/deployment/manage.do"
					method="post" onsubmit="return tt.validate();">
					<html:hidden property="houseId" />
					<html:hidden property="type" />
					<html:hidden name="saveAndSubmitFlag" property="saveAndSubmitFlag" value="${false}"/>
					<input type="hidden" name="createTime"
						value="${houseForm.createTime}">
					<input type="hidden" name="method" value="${houseForm.method}">
					<table border="0" cellspacing="2" cellpadding="3" align="left" align="center" style="margin-top: 10px;">
						<tr>
							<td width="200px"><div align="right">房源标题：</div></td>
							<td align="left" valign="middle"><html:text property="title" disabled="<%=readOnly?true:false%>"
									size="50" /> <html:errors property="title" /></td>
						</tr>
						<!-- ################## 基本信息 ######################### -->
						<tr>
							<td><div align="right">
									<bean:message key="info.area.1" />
									：
								</div></td>
							<td align="left"><html:select property="topAreaId" styleId="topAreaId"
									onchange="getAreas();" disabled="<%=readOnly?true:false%>">
									<html:option value=""></html:option>
									<html:options collection="tops" property="areaId"
										labelProperty="name" />
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">
									<bean:message key="info.area.2" />
									：
								</div></td>
							<td align="left"><html:select property="areaId" styleId="areaId" disabled="<%=readOnly?true:false%>">
									<html:option value=""></html:option>
									<html:options collection="lows" property="areaId"
										labelProperty="name" />
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">地址：</div></td>
							<td align="left"><html:text property="address" size="50" disabled="<%=readOnly?true:false%>"/>
								<html:errors property="address" /></td>
						</tr>
						<tr>
							<td><div align="right">面积：</div></td>
							<td align="left"><html:text onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')" property="space" size="50" disabled="<%=readOnly?true:false%>"/>
								<html:errors property="space" /></td>
						</tr>
						<%
							List<Config> cs = (List<Config>) request.getAttribute("cs");
								Set<Config> selectedConfigs = (Set<Config>) request
										.getAttribute("selectedConfigs");
						%>
						<tr>
							<td valign="top"><div align="right">房屋配置：</div></td>
							<td align="left" valign="top">
								<%
									for (int i = 0; i < cs.size(); i++) {
											Config c = cs.get(i);
											boolean checked = false;
											if (null != selectedConfigs) {
												for (Config s : selectedConfigs) {
													if (c.getConfigId() == s.getConfigId()) {
														checked = true;
														break;
													}
												}
											}
								%> <input name="configIds" type="checkbox" <%=readOnly?"disabled=\"disabled\"":""%>
								<%=checked ? "checked=\"checked\"" : ""%>
								value="<%=c.getConfigId()%>" /><%=c.getName()%>&nbsp;&nbsp; <%
 	if ((i + 1) % 6 == 0) {
 				out.print("<br/>");
 			}
 		}
 %> <input id="selectAllCheck" type="checkbox" <%=readOnly?"disabled=\"disabled\"":""%>
								<%=null != selectedConfigs
						&& cs.size() == selectedConfigs.size() ? "checked=\"checked\""
						: ""%>
								onclick="selectAll('configIds', this);" />全选
							</td>
						</tr>
						<tr>
							<td><div align="right">房源类型：</div></td>
							<td align="left"><html:select property="houseTypeId" disabled="<%=readOnly?true:false%>">
									<html:option value=""></html:option>
									<html:options collection="hts" property="houseTypeId"
										labelProperty="name" />
								</html:select></td>
						</tr>

						<tr>
							<td><div align="right">租借形式：</div></td>
							<td align="left"><html:select property="transaStatus" disabled="<%=readOnly?true:false%>">
									<html:option value="0">出租</html:option>
									<html:option value="1">出售</html:option>
									<html:option value="2">租售均可</html:option>
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">地铁线：</div></td>
							<td align="left"><html:select property="metroId" styleId="metroId" disabled="<%=readOnly?true:false%>"
									onchange="getStations();">
									<html:option value=""></html:option>
									<html:options collection="ms" property="metroId"
										labelProperty="name" />
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">地铁站：</div></td>
							<td align="left"><html:select property="metroStationId" disabled="<%=readOnly?true:false%>"
									styleId="metroStationId">
									<html:option value=""></html:option>
									<html:options collection="mss" property="stationId"
										labelProperty="name" />
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">物业类型：</div></td>
							<td align="left"><html:select property="propertyTypeId" disabled="<%=readOnly?true:false%>">
									<html:option value=""></html:option>
									<html:options collection="ppts" property="propertyTypeId"
										labelProperty="name" />
								</html:select></td>
						</tr>
						<tr>
							<td><div align="right">所属社区/街道办：</div></td>
							<td align="left" valign="middle"><html:text property="community" disabled="<%=readOnly?true:false%>"
									size="50" /> <html:errors property="community" /></td>
						</tr>
						<tr>
							<td><div align="right">管理费信息：</div></td>
							<td align="left" valign="middle"><html:text property="managePrice" disabled="<%=readOnly?true:false%>"
									size="50" /> <html:errors property="managePrice" /></td>
						</tr>
						<tr>
							<td><div align="right">总楼层：</div></td>
							<td align="left" valign="middle"><html:text property="floorAll" disabled="<%=readOnly?true:false%>"
									styleId="floorAll" size="50" /> <html:errors
									property="floorAll" /></td>
						</tr>
						<tr>
							<td><div align="right">所在楼层：</div></td>
							<td align="left" valign="middle"><html:text property="floorAt" disabled="<%=readOnly?true:false%>"
									styleId="floorAt" size="50" /> <html:errors property="floorAt" />
							</td>
						</tr>
						<tr> 
					      <td><div align="right">始建时间：</div></td>
					      <td align="left" valign="middle">
					        <input name="beginDate" id="beginDate" <%=readOnly?"disabled=\"disabled\"":""%>
					              value="<fmt:formatDate value='${houseForm.beginDate}' pattern='yyyy-MM-dd' />" />
					      </td>
					    </tr>
						<tr>
							<td><div align="right">房源介绍：</div></td>
							<td valign="middle">
							<html:textarea style="height: 473px;" property="intro" styleId="intro" disabled="<%=readOnly?true:false%>"></html:textarea>
							</td>
						</tr>
						<tr>
							<td><div align="right">地图信息：</div></td>
							<td>
							<html:textarea style="height: 473px;" property="mapInfo" styleId="mapInfo" disabled="<%=readOnly?true:false%>"></html:textarea>
							</td>
						</tr>
						<tr>
							<td><div align="right">备注：</div></td>
							<td align="left" >
							<html:textarea style="height: 150px; width: 760px; border: 1px solid #CCCCCC;" property="remark" styleId="remark" disabled="<%=readOnly?true:false%>"></html:textarea>
							<html:errors property="remark" />
							<div id="remarkErrorId" style="width: 35%;"></div>
							</td>
						</tr>
						<!-- ################## 基本信息 ######################### -->
						<tr>
							<td colspan="2"><div align="center">
								<% if (readOnly) { %>
								<button type="submit" class="">
									<bean:message key="display.back" />
								</button>
								<% } else { %>
								<button type="submit" class="">
									<bean:message key="display.save" />
								</button>
								<button type="submit" onclick="return changeBoolean()">
									<bean:message key="display.saveAndSubmit" />
								</button>
								<% } %>
								</div></td>
						</tr>
					</table>
				</html:form>
				<br>
				<jsp:include page="../../rooster.jsp"></jsp:include>
			</div>
		</div>
	</div>
</body>
</html>